/*
 * Created by JFormDesigner on Wed Oct 05 22:55:15 PDT 2011
 */

package com.thirdnf.calendar;

import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import javax.swing.*;
import com.jgoodies.forms.factories.*;
import com.jgoodies.forms.layout.*;
import com.toedter.calendar.*;
import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat;


/**
 * @author Joshua Gerth
 */
public class CalendarDialog extends JDialog {
    public CalendarDialog(Frame owner) {
        super(owner);
        initComponents();

        _dateField.setDateFormatter(DateTimeFormat.forPattern("MM/dd/yy"));
    }


    private void handleOkay() {
        dispose();
    }


    private void handleDateChange() {

        LocalDate date = _month.getDate();
    }


    private void handleToday() {
        _month.setDate(new LocalDate());
    }


    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        dialogPane = new JPanel();
        contentPanel = new JPanel();
        _month = new Month();
        calendar1 = new JCalendar();
        _dateField = new DateField();
        dateChooser1 = new JDateChooser();
        button1 = new JButton();
        buttonBar = new JPanel();
        okButton = new JButton();

        //======== this ========
        setModal(true);
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Calendar");
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

        //======== dialogPane ========
        {
            dialogPane.setBorder(Borders.DIALOG_BORDER);
            dialogPane.setLayout(new BorderLayout());

            //======== contentPanel ========
            {
                contentPanel.setLayout(new FormLayout(
                    "default, $lcgap, [50dlu,default]",
                    "3*(default, $lgap), default"));

                //---- _month ----
                _month.addPropertyChangeListener(new PropertyChangeListener() {
                    @Override
                    public void propertyChange(PropertyChangeEvent e) {
                        handleDateChange();
                    }
                });
                contentPanel.add(_month, CC.xy(1, 1));
                contentPanel.add(calendar1, CC.xy(3, 1));

                //---- _dateField ----
                _dateField.setToolTipText("mm/dd/yy");
                contentPanel.add(_dateField, CC.xy(1, 3));
                contentPanel.add(dateChooser1, CC.xy(3, 3));

                //---- button1 ----
                button1.setText("Today");
                button1.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        handleToday();
                    }
                });
                contentPanel.add(button1, CC.xy(1, 7));
            }
            dialogPane.add(contentPanel, BorderLayout.CENTER);

            //======== buttonBar ========
            {
                buttonBar.setBorder(Borders.BUTTON_BAR_GAP_BORDER);
                buttonBar.setLayout(new FormLayout(
                    "$glue, $button",
                    "pref"));

                //---- okButton ----
                okButton.setText("OK");
                okButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        handleOkay();
                    }
                });
                buttonBar.add(okButton, CC.xy(2, 1));
            }
            dialogPane.add(buttonBar, BorderLayout.SOUTH);
        }
        contentPane.add(dialogPane, BorderLayout.CENTER);
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JPanel dialogPane;
    private JPanel contentPanel;
    private Month _month;
    private JCalendar calendar1;
    private DateField _dateField;
    private JDateChooser dateChooser1;
    private JButton button1;
    private JPanel buttonBar;
    private JButton okButton;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
